﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class admin_cms_default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                Load_Logo();
            }


        }

    }
    protected void Load_Logo()
    {
        DataTable dtlogo = new DataTable();

        dtlogo = DataAccess.ExeSQLToDataTable("select * from Logo");

        if (dtlogo.Rows.Count > 0)
        {
            GridView1.DataSource = dtlogo;
            GridView1.DataBind();
        }
    }
    protected void bt_delete_yahoo(object sender, EventArgs e)
    {

    }

    protected void grv_yahoo_click(object sender, CommandEventArgs e)
    {

        string Id = e.CommandArgument.ToString();
        string CheckName = e.CommandName.ToString();
        if (CheckName == "X")
        {

            DataAccess.ExeNonSQL("delete from Logo where Id='" + Id + "'");
            Response.Write("<script>alert('Bạn xóa thành công 1 bản ghi')</script>");
            Load_Logo();
        }
        else
        {
            DataTable dtgrv_logo = new DataTable();
            dtgrv_logo = DataAccess.ExeSQLToDataTable("select * from Logo");
            if (dtgrv_logo.Rows.Count > 0)
            {
                //txtname.Text = dtgrv_logo.Rows[0][1].ToString();

                Session.Add("Id", Id);
            }
        }
    }
    protected void Logo_Insert(object sender, EventArgs e)
    {
        string filename = Fileuplogo.FileName;
        if (filename == "")
        {
            Response.Write("<script>alert('Bạn chưa chọn logo')</script>");
        }
        else
        {
            Server.MapPath("../files_upload/images/" + filename);
            DataAccess.ExeNonSQL("Insert into Logo(Image) values(N'" + filename + "')");
            Response.Write("<script>alert('Bạn thêm thành công 1 bản ghi')</script>");
            Load_Logo();
        }


        

    }
    protected void Logo_update(object sender, EventArgs e)
    {
        int Id = Convert.ToInt32(Session["Id"].ToString());
        string filename = Fileuplogo.FileName;
        if (filename == "")
        {
            Response.Write("<script>alert('Bạn chưa chọn logo')</script>");
        }
        else
        {
            Server.MapPath("../files_upload/images/" + filename);
            DataAccess.ExeNonSQL("Update Logo set Image=N'"+filename+"' where Id='"+Id+"'");
            Response.Write("<script>alert('Bạn thêm thành công 1 bản ghi')</script>");
            Load_Logo();
        }
    }
}
